package icu.gking.cart_system.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import icu.gking.cart_system.pojo.Cart;
import icu.gking.cart_system.service.CartService;
import icu.gking.cart_system.mapper.CartMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;

/**
* @author avery
* @description 针对表【cart(购物车表)】的数据库操作Service实现
* @createDate 2024-12-03 16:40:04
*/
@Service
public class CartServiceImpl extends ServiceImpl<CartMapper, Cart>
    implements CartService{

    @Override
    @Transactional(readOnly = true)
    public List<Cart> list(Wrapper<Cart> queryWrapper) {
        // 确保每次都从数据库查询最新数据
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    @Transactional
    public boolean save(Cart entity) {
        // 添加创建时间和更新时间
        if (entity.getCreateTime() == null) {
            entity.setCreateTime(new Date());
        }
        entity.setUpdateTime(new Date());
        return super.save(entity);
    }

    @Override
    @Transactional
    public boolean updateById(Cart entity) {
        // 更新修改时间
        entity.setUpdateTime(new Date());
        return super.updateById(entity);
    }
}




